#include<vector>
#include<iostream>
#include<queue>
using namespace std;

class Solution {
public:
    bool vis[205][205];
    int m, n;
    int dx[4] = { 0,0,-1,1 };
    int dy[4] = { -1,1,0,0 };

    void dfs(vector<vector<char>>& board, int i, int j)
    {
        for (int k = 0; k < 4; k++)
        {
            int x = dx[k] + i;
            int y = dy[k] + j;
            if (x >= 0 && x < m && y >= 0 && y < n && !vis[x][y] && board[x][y] == 'O')
            {
                vis[x][y] = true;
                dfs(board, x, y);
            }
        }
    }

    void solve(vector<vector<char>>& board) {
        m = board.size(), n = board[0].size();
        for (int i = 0; i < m; i++)
        {
            if (!vis[i][0] && board[i][0] == 'O')
            {
                vis[i][0] = true;
                dfs(board, i, 0);
            }
            if (!vis[i][n - 1] && board[i][n - 1] == 'O')
            {
                vis[i][n - 1] = true;
                dfs(board, i, n - 1);
            }
        }
        for (int i = 0; i < n; i++)
        {
            if (!vis[0][i] && board[0][i] == 'O')
            {
                vis[0][i] = true;
                dfs(board, 0, i);
            }
            if (!vis[m - 1][i] && board[m - 1][i] == 'O')
            {
                vis[m - 1][i] = true;
                dfs(board, m - 1, i);
            }
        }

        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (!vis[i][j] && board[i][j] == 'O')
                {
                    board[i][j] = 'X';
                }
            }
        }
    }

};
int main()
{
    vector<vector<char>> board = { {'O','O','O'},{'O','X','O'},{'O','O','O'} };
    solve(board);
}